<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>实现深克隆数组</title>
</head>
<body>
<script>
    //原数组
    var arr1 = [33, 44, 11, 22, [77, 88, [33, 44]]];

    //函数，这个函数会被递归
    function deepClone(arr) {
        //结果数组,"每一层"都有一个结果数组
        var result = [];
        //遍历数组的每一项
        for (var i = 0; i < arr.length; i++) {
            //类型判断，如果遍历到的项是数组
            if (Array.isArray(arr[i])) {
                //递归
                result.push(deepClone(arr[i]))
            } else {
                //如果遍历到的项不是数组，是基本类型，就直接推入数组
                result.push(arr[i])
            }
        }
        //返回结果数组
        return result;
    }

    //测试一下
    var arr2 = deepClone(arr1);
    console.log(arr2);

    //是否藕断丝连
    console.log(arr1[4][2] == arr2[4][2]);
    arr1[4][2].push(99);
    console.log(arr1);
    console.log(arr2);
</script>
</body>
</html>